﻿using System.Linq.Expressions;

namespace eg_30_异常处理
{
    internal class Program
    {
        static void Main(string[] args)
        {
            int number = 0;
            while (true)
            {
                try
                {
                    Console.WriteLine("输入一个属");
                    number = int.Parse(Console.ReadLine());
                    if (number < 0 || number > 100)
                        throw new ArgumentOutOfRangeException("number", "数值在1-100");
                }


                catch (ArgumentOutOfRangeException e)
                {
                    Console.WriteLine(e.Message);
                    continue;
                }
                catch (FormatException e)
                {
                    Console.WriteLine(e.Message);
                    number = 100;
                    continue;
                }
            }
        }
    }
}

/*
    try
    {
    抛出异常语句块
    }
    catch (异常类型1 异常类型变量名1)
    {
    异常处理语句块1
    }
    ……
    catch(异常类型n 异常类型变更名n)
    {
    异常处理语句块n
    }
    finally
    {
    资源释放语句块
    }
*/